package emf2gwtbridge;

import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;

public class GeneratorUtils {
	public static String getProxyPackage(GenPackage p) {
		return startPath(p) + "client.dto";
	}

	private static String startPath(GenPackage p) {
		if (p.getBasePackage() == null)
			return "";
		return p.getBasePackage() + ".";
	}

	public static String getRequestPackage(GenPackage p) {
		return startPath(p) + "client.request";
	}

	public static String getRequestFactoryPackage(GenPackage p) {
		return startPath(p) + "client.request";
	}

	public static String getProxyClassName(GenClass c) {
		return c.getClassName() + "Proxy";
	}

	public static String getRequestClassName(GenClass c) {
		return c.getClassName() + "Request";
	}

	public static String getRequestFcnName(GenClass c) {
		String firstCharacter = c.getClassName().substring(0, 1).toLowerCase();
		return firstCharacter + c.getClassName().substring(1) + "Request";
	}

	public static String getRequestFactoryClassName(GenPackage p) {
		return p.getPackageName() + "RequestFactory";
	}

	public static String getServiceClassName(GenClass c) {
		return c.getClassName() + "Service";
	}

	public static String getServicePackage(GenPackage p) {
		return startPath(p) + "service";
	}

	public static String getType(GenFeature f) {
		String c = "java.util.List";
		if (!f.getEcoreFeature().isOrdered())
			c = "java.util.Set";
		StringBuffer sb = new StringBuffer(f.getGenModel().getImportedName(c));
		sb.append("<");
		sb.append(f.getGenModel().getImportedName(f.getListItemType(null)));
		if (!f.getListItemType(null).equals("Double"))
			sb.append("Proxy");
		sb.append(">");
		return sb.toString();
	}

	public static String getServiceLocatorClassName(GenPackage p) {
		return p.getPackageName() + "ServiceLocator";
	}

	public static String getServiceLocatorPackageName(GenPackage p) {
		return startPath(p) + "service";
	}
}
